<template>
    <div class="app-container">
      <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
        <el-form-item label="药品名称" prop="drugName">
          <el-input
            v-model="queryParams.drugName"
            placeholder="请输入药品名称"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="Search" @click="getOrderId">搜索</el-button>
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button
            type="warning"
            plain
            icon="Download"
            @click="handleExport"
            v-hasPermi="['medicine:order:export']"
          >导出</el-button>
        </el-col>
        <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
      </el-row>
  
      <el-table v-loading="loading" :data="orderList.hisMedicineOrderDetailList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column label="详情ID" align="center" prop="detailId" />
        <el-table-column label="药品名称" align="center" prop="hisMedicineDrug.drugName" />
        <el-table-column label="数量" align="center" prop="detailNum" />
        <el-table-column label="订单ID" align="center" prop="orderId" />
        <el-table-column label="创建时间" align="center" prop="createTime" />
      </el-table>
      
  
    </div>
  </template>
  
  <script setup name="Order">
  import { listOrder, getOrder, delOrder, addOrder, updateOrder } from "@/api/his/order.js";
  
  const { proxy } = getCurrentInstance();
  const { order_status } = proxy.useDict('order_status');
  const router = useRoute();
  
  const orderList = ref([]);
  const open = ref(false);
  const loading = ref(true);
  const showSearch = ref(true);
  const ids = ref([]);
  const single = ref(true);
  const multiple = ref(true);
  const total = ref(0);
  const title = ref("");
  const data = reactive({
    form: {},
    queryParams: {
      pageNum: 1,
      pageSize: 10,
      orderId: null,
      drugName: null,
    },
    rules: {
      orderPerson: [
        { required: true, message: "制单人不能为空", trigger: "change" }
      ],
      supplierId: [
        { required: true, message: "供应商ID不能为空", trigger: "change" }
      ],
    }
  });
  
  const { queryParams, form, rules } = toRefs(data);
  
  

  /** 查询订单信息列表 */
  function getOrderId() {
    queryParams.value.orderId = router.params.orderId
    loading.value = true;
    getOrder(queryParams.value).then(response => {
      orderList.value = response.data;
      total.value = response.total;
      loading.value = false;
    });
  }
  
  // 取消按钮
  function cancel() {
    open.value = false;
    reset();
  }
  
  
  /** 搜索按钮操作 */
  function handleQuery() {
    queryParams.value.pageNum = 1;
    getOrderId();
  }
  
  /** 重置按钮操作 */
  function resetQuery() {
    proxy.resetForm("queryRef");
    handleQuery();
  }
  
  // 多选框选中数据
  function handleSelectionChange(selection) {
    ids.value = selection.map(item => item.orderId);
    single.value = selection.length != 1;
    multiple.value = !selection.length;
  }
  
  
  /** 修改按钮操作 */
  function carList() {
    router.push("/medicine/car_list/carList")
  }
  
  
  /** 导出按钮操作 */
  function handleExport() {
    proxy.download('medicine/order/export', {
      ...queryParams.value
    }, `order_${new Date().getTime()}.xlsx`)
  }
  
  getOrderId();
  </script>
  